import { useUserInfoStore } from '@/store/userInfo'

const hasPermi = {
  mounted(el:any, binding: any, vnode: any) {
    const { value } = binding
    const userInfoStore = useUserInfoStore()
    const all_permission: string = "*:*:*"
    const permissions: any = userInfoStore.permissions

    if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value

      const hasPermissions = permissions.some((permission: any) => {
        return all_permission === permission || permissionFlag.includes(permission)
      })

      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  }
}

export default hasPermi
